package com.mrd.util;

import java.lang.reflect.Field;

/**
 * <p>
 * application name: sample
 * <p>
 * copyright: Copyright@2012 明睿达科技有限公司
 */
/**
 * 反射工具类
 * @author winaya
 */
public class ReflectUtil {
	/**
	 * 根据名称获取字段
	 * @param name
	 * @param entityClass
	 * @return
	 */
	@SuppressWarnings("rawtypes")
	public static Field getField(String name,Class entityClass) {
		Field field = null;
		try {
			field = entityClass.getDeclaredField(name);
		} catch (SecurityException e) {
			e.printStackTrace();
		} catch (NoSuchFieldException e) {
			Class cl = entityClass.getSuperclass();
			if(cl != null) {
				field = getField(name, cl);
			}
		}
		return field;
	}
}
